//
//  PlusImageButton.m
//  WuliHanhan
//
//  Created by chen tang on 16/3/1.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "PlusImageButton.h"

@interface PlusImageButton ()


@property (nonatomic, assign) BOOL haveImage;


@end


@implementation PlusImageButton

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
     
        [self initUI];
        [self addTarget:self action:@selector(judgePush) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}



- (void)initUI
{
    UIImage *image = [UIImage imageNamed:@""];
    [self setBackgroundImage:image forState:UIControlStateNormal];
}



- (void)setPlusImage:(UIImage *)plusImage
{
    [self setBackgroundImage:plusImage forState:UIControlStateNormal];
    //加载图片
    _haveImage = YES;
    
}



//判断是选择照片还是编辑照片
- (void)judgePush
{
    //如果有图片进入编辑
    if (_haveImage)
    {
        if ([_MPlusImageButtonDelegate respondsToSelector:@selector(editeOldImage)]){
            [_MPlusImageButtonDelegate editeOldImage];
        }
        
    }
    //如果没有图片，选择图片
    else
    {
        if ([_MPlusImageButtonDelegate respondsToSelector:@selector(pushSelectNewImage)]) {
            
            [_MPlusImageButtonDelegate pushSelectNewImage];
        }
        
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
